<template>
  <div>
    <van-address-list
      :list="list"
      default-tag-text="默认"
      @edit="onEdit"
      @add="onAdd"
      add-button-text="+ 新建收货地址"
      @select="change($event)"
    />
    <van-empty v-if="list.length == 0" description="暂无数据" />
  </div>
</template>

<script>
import { Toast } from "vant";
import { reqAddressList, reqEditAddress } from "../../http/http";
export default {
  data() {
    return {
      list: [
        // {
        //   id: '1',
        //   name: '张三',
        //   tel: '13000000000',
        //   address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
        //   isDefault: true,
        // },
      ],
    };
  },
  methods: {
    onEdit(e) {
      this.$router.push("/addAddress?id=" + e.id);
    },
    onAdd() {
      this.$router.push("/addAddress");
    },
    change(e) {
      if (!(this.$route.query.id)) {
        this.$router.push("/confirmOrder?id=" + e.id);
      }
    },
  },
  activated() {
    reqAddressList({
      uid: JSON.parse(localStorage.getItem("userInfo")).uid,
    }).then((res) => {
      if (res.data.code == 200) {
        let arr = res.data.list ? res.data.list : [];
        this.list = arr.map((item) => {
          return {
            id: item.id,
            name: item.username,
            tel: item.userphone,
            address: item.location + item.useraddress,
            isDefault: item.status === 1,
          };
        });
        // let data = res.data.list ? res.data.list : [];
        // if(this.list.length>0){
        //   this.list.forEach((item)=>{

        //   })
        // }
        // data.forEach((item) => {
        //   let obj = {
        //     id: item.id,
        //     name: item.username,
        //     tel: item.userphone,
        //     address: item.location + item.useraddress,
        //     isDefault: item.status == 1,
        //     label: item.label,
        //   };
        //   this.list.push(obj);
        // });
      }
    });
  },
};
</script>

<style scoped>
</style>